FMI Ticket System
| Kamen Mladenov | FMI Computer Science Year 1 Group 6 | Project 1 | Project Topic 4 |
Public Member Functions | Friends | List of all members
String Class Reference

Public Member Functions

 String (unsigned length)
 The underlying array is allocated with length (+ 1) size. More...
 
 String (const char *str)
 Copies str. More...
 
const char * get_cstr () const
 Returns internal C-style string.
 
unsigned get_length () const
 Returns number of characters in string.
 
char & operator[] (unsigned index)
 Returns a character reference (from the underlying C-style string) at the given index.
 
String & operator+= (const char *str)
 Appends a C-style string. More...
 
String & operator+= (unsigned number)
 Appends a number. More...
 
 String (const String &other)
 
String & operator= (const String &other)
 
 String (String &&other)
 
String & operator= (String &&other)
 
void read (std::istream &istr)
 Reads String from stream. More...
 
void write (std::ostream &ostr) const
 Writes String to stream. More...
 
int compare (const String &other) const
 Compares two strings. More...
 

Friends

std::istream & operator>> (std::istream &istr, String &event)
 Reads String from stream with >> operator. More...
 
std::ostream & operator<< (std::ostream &ostr, const String &event)
 Writes String to stream with << operator. More...
 

Constructor & Destructor Documentation

◆ String() [1/2]

String::String ( unsigned  length)

The underlying array is allocated with length (+ 1) size.

Allocated with length + 1 size, so there is a terminating zero at the end.

◆ String() [2/2]

String::String ( const char *  str)

Copies str.

\params str C-style string

Member Function Documentation

◆ compare()

int String::compare ( const String &  other) const

Compares two strings.

\params other C-style string

Returns
strcmp between underlying C-style string and "other"

◆ operator+=() [1/2]

String & String::operator+= ( const char *  str)

Appends a C-style string.

\params str C-style string

◆ operator+=() [2/2]

String & String::operator+= ( unsigned  number)

Appends a number.

Converts the number to a C-style string and then uses += to append it.

◆ read()

void String::read ( std::istream &  istr)

Reads String from stream.

Parameters
istrAn input stream

Directly reads bytes from stream (calls read() function). First reads the string length, then the underlying C-style string (including terminating zero).

Remarks
Doesn't alter the stream in any other way.
Note
Best used with binary ifstream

◆ write()

void String::write ( std::ostream &  ostr) const

Writes String to stream.

Parameters
ostrAn output stream

Directly writes bytes to stream (calls write() function). First writes the string length, then the underlying C-style string (including terminating zero).

Remarks
Doesn't alter the stream in any other way.
Note
Best used with binary ofstream

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  ostr,
const String &  event 
)
friend

Writes String to stream with << operator.

Uses the stream's << operator to write the underlying C-style string

Note
Best used with std::cout or text std::ofstream

◆ operator>>

std::istream & operator>> ( std::istream &  istr,
String &  event 
)
friend

Reads String from stream with >> operator.

Uses the stream's getline function to read the data.

Warning
It takes at most 1024 characters from the stream!
Note
Best used with std::cin or text std::ifstream

The documentation for this class was generated from the following files: